<template>
  <div>

    <div class="header-top">
      <p>梦想只要能持久，就能成为现实。我们不就是生活在梦想中的吗？——丁尼生</p>
    </div>
    <div class="header">
      <div class="header-cont">
        <div class="left" :span="3">
          <a href="/"><img src="@/assets/1.svg"></a>
        </div>
        <nav class="nav" :span="10">


          <router-link v-if="!value.is_site" :class="{this:number===index}" @click.native="number=index"
                       v-for="(value,index) in course_list" :key="index.id" :to="value.link">
            <li class="tag-link">{{value.title}}</li>
          </router-link>
          <a :href="value.link" v-else>
            <li>{{value.title}}</li>
          </a>
          <!--            <a :href="value.link" v-else><li>{{value.title}}</li></a>-->


          <!--          <router-link  to=/courses>-->
          <!--            <li>免费课</li>-->
          <!--          </router-link>-->
          <!--          <a href="">-->
          <!--            <li>实战课</li>-->
          <!--          </a>-->
          <!--          <a href="">-->
          <!--            <li>轻课</li>-->
          <!--          </a>-->
          <!--          <a href="">-->
          <!--            <li>就业班</li>-->
          <!--          </a>-->
          <!--          <a href="">-->
          <!--            <li>题库</li>-->
          <!--          </a>-->
          <!--          <a href="">-->
          <!--            <li>学员成果</li>-->
          <!--          </a>-->
        </nav>
        <div class="header-right-box" :span="11">
          <div class="search">
            <input @blur="inputShowHandler" type="text" placeholder="请输入想搜索的课程" v-show="!show" ref="Input" id="Input">
            <ul @click="ulShowHandler" v-show="show">
              <span>Python</span>
              <span>Linux</span>
            </ul>
          </div>
          <!--          搜索图片-->
          <!--          <p>-->
          <!--            <img src="//hcdn2.luffycity.com/media/frontend/activity/sousuo1_1572509512.0016685.png" alt="">-->
          <!--            <img src="//hcdn2.luffycity.com/media/frontend/activity/sousuo2_1572509511.9415796.png" alt="">-->
          <!--            <img src="//hcdn2.luffycity.com/media/frontend/activity/new_1572509511.5792108.png" alt="">-->
          <!--          </p>-->

          <!--          购物车-->
          <router-link to="/Cart" class="shop-car" v-show="token">
            <img src="//hcdn2.luffycity.com/media/frontend/activity/shopcart@2x_1568185801.2089324.png" alt="">
            <span>购物车</span>
          </router-link>
          <div class="nav-right-box" v-show="token">
            <div class="nav-right">
              <router-link to="/myclass" style="text-decoration: none">
                <div class="nav-study"  @mouseover="personInfoList">我的教室</div>
              </router-link>
              <div class="nav-img" @mouseover="personInfoList" @mouseout="personInfoOut">
                <!--                <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1594914855958&di=6723cbe9d9d01c5e3272f877ad37f940&imgtype=0&src=http%3A%2F%2Fa0.att.hudong.com%2F02%2F93%2F01300543893970147279933938013_s.jpg" alt="" style="border: 1px solid rgb(243, 243, 243);">-->
                <ul class="home-my-account" v-show="list_status"
                    @mouseover="personInfoList">
                  <li>
                    我的账户
                    <!--                    <img src="https://hcdn1.luffycity.com/static/frontend/activity/back_1568185800.821227.svg" alt="">-->
                  </li>
                  <li>
                    我的订单
                    <!--                    <img src="https://hcdn1.luffycity.com/static/frontend/activity/back_1568185800.821227.svg" alt="">-->
                  </li>
                  <li>
                    ⻉⾥⼩卖铺
                    <!--                    <img src="https://hcdn1.luffycity.com/static/frontend/activity/back_1568185800.821227.svg" alt="">-->
                  </li>
                  <li>
                    我的优惠券
                    <!--                    <img src="https://hcdn1.luffycity.com/static/frontend/activity/back_1568185800.821227.svg" alt="">-->
                  </li>
                  <li>
                 <span>
                 我的消息
                 <b>(26)</b>
                 </span>
                    <!--                    <img src="https://hcdn1.luffycity.com/static/frontend/activity/back_1568185800.821227.svg" alt="">-->
                  </li>
                  <li @click="loginouthandler">
                    退出
                    <!--                    <img src="https://hcdn1.luffycity.com/static/frontend/activity/back_1568185800.821227.svg" alt="">-->
                  </li>
                </ul>
              </div>
            </div>
          </div>

            <div class="auth-button">
              <router-link to="/login">
                <button class="signin" v-show="!token">登录</button>
              </router-link>
              <router-link to="/register" class="signup " v-show="!token">注册领好课</router-link>
            </div>
          </div>
        </div>
      </div>
    </div>
</template>

<script>
  import settings from "../../settings";

  export default {
    name: "Header",
    data() {
      return {
        list_status: false,
        show: true,
        token: true,
        // course: [
        //   {"name": '免费课', "path": '/courses'},
        //   {"name": '实战课', "path": "/shizhan"},
        //   {"name": '轻课', "path": "/"},
        //   {"name": '题库', "path": "/"},
        //   {"name": '学员成果', "path": "/"},
        // ],
        course_list: [],
        number: 20
      }

    },

    methods: {
      get_nav_data() {
        this.$axios.get(`${(settings.Host)}/home/nav/`)
          .then((res) => {
            // console.log(res)
            this.course_list = res.data;
          })
          .catch((error) => {
            console.log(error.response)
          })
      },

      check_login_status() {
        this.token = sessionStorage.user_token || localStorage.user_token
      },
      // 注销
      loginouthandler(){
        localStorage.removeItem('user_id');
        localStorage.removeItem('user_name');
        localStorage.removeItem('user_token');
        sessionStorage.removeItem('user_id');
        sessionStorage.removeItem('user_name');
        sessionStorage.removeItem('user_token');

        this.check_login_status()
      },

      ulShowHandler() {
        this.show = false
        console.log(this.$refs.Input);
        this.$nextTick(() => {
          this.$refs.Input.focus();
        })

      },
      personInfoList() {
        this.list_status = true;
      },
      personInfoOut() {
        this.list_status = false;
      },
      inputShowHandler() {
        this.show = true
      },


    },
    created() {
      this.get_nav_data();
      this.check_login_status();
    },
  }
</script>

<style scoped>

  .header {
    width: 100%;
    height: 60px;
    background: #fff;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    border-bottom: 1px solid hsla(0, 0%, 59.2%, .1);
  }

  .header-top {
    width: 100%;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fafafa;

  }

  .header-top p {
    width: 1200px;
    font-size: 12px;
    cursor: pointer;
    color: #9d9d9d;
  }


  .header .header-cont {
    width: 1200px;
    height: 100%;
    display: flex;
    align-items: center;
    position: relative;
  }

  .header .header-cont .nav {
    width: auto;
    height: 36px;
    display: flex;
    line-height: 36px;
    margin-left: 160px;
  }


  .header .header-cont .nav .this li {
    color: #f5a623;

  }

  .header .header-cont .nav li {
    list-style-type: none;
  }

  .header .header-cont .nav a li {
    font-size: 15px;
    font-weight: 400;
    cursor: pointer;
    color: #4a4a4a;
    list-style-type: none;
  }


  .header .header-cont .nav a:hover {
    border-bottom: 2px solid #f5a623
  }

  .header .header-cont .nav a {
    text-decoration: none;
    display: inline-block;
    margin-right: 30px;
  }

  .header .header-cont .header-right-box {
    height: 100%;
    display: flex;
    align-items: center;
    font-size: 15px;
    color: #4a4a4a;
    position: absolute;
    right: 0;
    top: 0;
  }

  .header .header-cont .header-right-box .search {
    height: auto;
    display: flex;
  }

  .header .header-cont .header-right-box .search input {
    width: 185px;
    height: 26px;
    font-size: 14px;
    color: #4a4a4a;
    border-bottom: 3px solid #ffc210;

  }

  .header .header-cont .header-right-box .search ul {
    width: 185px;
    height: 26px;
    display: flex;
    align-items: center;
    padding-bottom: 3px;
    border-bottom: 1px solid hsla(0, 0%, 59.2%, .25);
    cursor: text;
  }

  .header .header-cont .header-right-box .shop-car {
    color: #333;
    width: 99px;
    height: 28px;
    border-radius: 15px;
    margin-right: 20px;
    background: #f7f7f7;
    /*display: inline-block;*/
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    text-decoration: none;
  }

  .header .header-cont .header-right-box .shop-car img {
    width: 20px;
    height: 20px;
    margin-right: 7px;
  }


  .header .header-cont .header-right-box .search ul span {
    color: #545c63;
    font-size: 12px;
    padding: 3px 12px;
    background: #eeeeef;
    cursor: pointer;
    margin-right: 3px;
    border-radius: 11px;
  }

  .header .header-cont .header-right-box .auth-button {
    height: 36px;
    display: flex;
    align-items: center;
    line-height: 36px;
  }

  .header .header-cont .header-right-box .auth-button .signin {
    width: 76px;
    border: 1px solid #ffc210;
    color: #ffc210;
    margin-right: 14px;
    margin-left: 5px;
  }

  .header .header-cont .header-right-box .auth-button .signin, .header .header-cont .header-right-box .auth-button .signup {
    cursor: pointer;
    border-radius: 4px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    white-space: nowrap;
    font-weight: 500;
  }

  .header .header-cont .header-right-box .auth-button a {
    text-decoration: none;
  }

  .header .header-cont .header-right-box .auth-button a .signin {
    width: 98px;
    background: #ffc210;
    color: #fff;

  }

  .header .header-cont .header-right-box .auth-button .signup {
    width: 98px;
    background: #ffc210;
    color: #fff;
    text-decoration: none;
  }


  .nav-right-box {
    position: relative;
  }

  .nav-right-box .nav-right {
    float: right;
    display: flex;
    height: 100%;
    line-height: 60px;
    position: relative;
  }

  .nav-right .nav-study {
    font-size: 15px;
    font-weight: 300;
    color: #5e5e5e;
    margin-right: 20px;
    cursor: pointer;
  }

  .nav-right .nav-study:hover {
    color: #000;
  }

  .nav-right .nav-study{
   color: #333;
    width: 99px;
    height: 28px;
    border-radius: 15px;
    margin-right: 20px;
    background: #f7f7f7;
    /*display: inline-block;*/
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    text-decoration: none;
  }

  .nav-img img {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: inline-block;
    cursor: pointer;
  }

  .home-my-account {
    position: absolute;
    right: 0;
    top: 60px;
    z-index: 101;
    width: 190px;
    height: auto;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 4px 8px 0 #d0d0d0;
  }

  li {
    list-style: none;
  }

  .home-my-account li {
    height: 40px;
    font-size: 14px;
    font-weight: 300;
    color: #5e5e5e;
    padding-left: 20px;
    padding-right: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
  }

  .home-my-account li img {
    cursor: pointer;
    width: 5px;
    height: 10px;
  }

  .home-my-account li span {
    height: 40px;
    display: flex;
    align-items: center;
  }

  .home-my-account li span b {
    font-weight: 300;
    margin-top: -2px;
  }
</style>
